# 获取亚让

# 接口url：https://vip.titan007.com/AsianOdds_n.aspx?id=2809940&t=0&l=0
# 页面url：https://vip.titan007.com/AsianOdds_n.aspx?id=2809940&l=0
from bs4 import BeautifulSoup

import requests

url = "https://vip.titan007.com/AsianOdds_n.aspx?id=2809940&t=0&l=0"

payload={}
headers = {
   'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
   'accept-language': 'zh-CN,zh;q=0.9',
   'cache-control': 'max-age=0',
   'if-modified-since': 'Sat, 27 Sep 2025 14:22:02 GMT',
   'priority': 'u=0, i',
   'referer': 'https://vip.titan007.com/AsianOdds_n.aspx?id=2809940&t=1&l=0',
   'sec-ch-ua': '"Chromium";v="140", "Not=A?Brand";v="24", "Google Chrome";v="140"',
   'sec-ch-ua-mobile': '?0',
   'sec-ch-ua-platform': '"Windows"',
   'sec-fetch-dest': 'document',
   'sec-fetch-mode': 'navigate',
   'sec-fetch-site': 'same-origin',
   'sec-fetch-user': '?1',
   'upgrade-insecure-requests': '1',
   'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36',
   'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6309071d) XWEB/8461 Flue',
   'Host': 'vip.titan007.com',
   'Connection': 'keep-alive'
}

response = requests.request("GET", url, headers=headers, data=payload)


html_content = response.text


soup = BeautifulSoup(html_content, 'html.parser')

# 找到角球数据表格
table = soup.find('table', {'id': 'odds'})

corner_data = []

# 遍历表格行，跳过表头
for row in table.find_all('tr')[2:]:  # 跳过前两行表头
    cells = row.find_all('td')
    if len(cells) < 10:
        continue

    # 如果是display: none;的行，则跳过
    if cells[0].get('style', '') == 'display: none;':
        continue

    tds = row.find_all('td')

    # 获取公司ID - 在第三个tr的company_id 属性中

    # 获取公司ID - 在第三个td中的span标签中
    company_id_cell = tds[2] if len(tds) > 2 else None
    company_id = None
    if company_id_cell:
        company_span = company_id_cell.find('span')
        if company_span and company_span.get('companyID'):
            company_id = company_span.get('companyID')
        elif company_span and company_span.get('companyid'):  # 兼容小写
            company_id = company_span.get('companyid')

    if not company_id:
        continue

    company = company_id

    # 初盘数据
    initial_home = cells[1].get_text(strip=True)
    initial_handicap = cells[2].get_text(strip=True)
    initial_away = cells[3].get_text(strip=True)

    # 终盘数据 - 查找具有 oddstype="wholeOdds" 的单元格
    final_cells = row.find_all('td', {'oddstype': 'wholeOdds'})
    if len(final_cells) >= 3:
        final_home = final_cells[0].get_text(strip=True)
        final_handicap = final_cells[1].get_text(strip=True)
        final_away = final_cells[2].get_text(strip=True)
    else:
        final_home = final_handicap = final_away = "N/A"

    corner_data.append({
        'company': company,
        'initial': {
            'home': initial_home,
            'handicap': initial_handicap,
            'away': initial_away
        },
        'final': {
            'home': final_home,
            'handicap': final_handicap,
            'away': final_away
        }
    })

# 打印结果
for data in corner_data:
    print(f"公司: {data['company']}")
    print(f"初盘: 主队 {data['initial']['home']}, 盘口 {data['initial']['handicap']}, 客队 {data['initial']['away']}")
    print(f"终盘: 主队 {data['final']['home']}, 盘口 {data['final']['handicap']}, 客队 {data['final']['away']}")
    print()